<?php
	function habilitation()
	{
		$hab = array(
			1,
			2
		);
		
		if (in_array(get_s('bo_user_role'), $hab))
			return true;
		return false;
	}
	
	function view($table, $id)
	{
		if (habilitation())
		{
			$retour = array();
			
			$php = '$x = 20;
$p = "tata";';
			$retour["php"] = $php;
			
			$champs = champs();
			$champaff = '';
			foreach ($champs as $champ)
				$champaff .= $champ['id'] . ', ';
			$champaff = substr($champaff, 0, -2);
			$gp_db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
			$sql = "SELECT $champaff FROM $table WHERE id = $id";
			$tab = $gp_db -> fetchArray_one($sql);
			
			foreach ($tab as $cle => $valeur)
			{
				$type = $champs[$cle]["type"];
				if ($type == 'input')
					$retour[$champs[$cle]["Affichage"]] = sl($valeur);
				if ($type == 'textarea')
					$retour[$champs[$cle]["Affichage"]] = nl2br(sl($valeur));
				else if ($type == 'password')
					$retour[$champs[$cle]["Affichage"]] = '***';
				else if ($type == 'select')
				{
					$type_select = $champs[$cle]["typeselect"];
					
					if ($type_select == 'vocabulaire')
					{
						$vocabulaire = $champs[$cle]["data"];
						$tabvoc = explode(';', $vocabulaire);
						
						foreach ($tabvoc as $seg)
						{
							list($seg_c, $seg_v) = explode('%%', $seg, 2);
							if ($seg_c == $valeur)
							{
								$retour[$champs[$cle]["Affichage"]] = sl($seg_v);
								break;
							}
						}
					}
					
					else if ($type_select == 'sql')
					{
						$requete = $champs[$cle]["data"];
						$tagseg = $gp_db -> fetchRow($requete);
						foreach ($tagseg as $ligne)
						{
							if ($ligne[0] == $valeur)
							{
								$retour[$champs[$cle]["Affichage"]] = sl($ligne[1]);
								break;
							}
						}
					}
				}
			}
			
			return $retour;
		}
		return false;
	}
	
	function champs()
	{
		$retour = array();
		
				$retour["date_track"]["id"] = "date_track";
		$retour["date_track"]["Affichage"] = "Date";
		$retour["date_track"]["type"] = "date";
		$retour["date_track"]["max"] = 255;
		
		$retour["date_track"]["defaut"] = "";
		$retour["date_track"]["js"] = "return false;";
		$retour["date_track"]["obligatoire"] = true;
		$retour["date_track"]["tri"] = true;
		$retour["date_track"]["filtre"] = true;

		$retour["ip"]["id"] = "ip";
		$retour["ip"]["Affichage"] = "Adresse IP";
		$retour["ip"]["type"] = "input";
		$retour["ip"]["max"] = 255;
		
		$retour["ip"]["defaut"] = "";
		$retour["ip"]["js"] = "return false;";
		$retour["ip"]["obligatoire"] = true;
		$retour["ip"]["tri"] = true;
		$retour["ip"]["filtre"] = true;

		$retour["page_track"]["id"] = "page_track";
		$retour["page_track"]["Affichage"] = "Page";
		$retour["page_track"]["type"] = "input";
		$retour["page_track"]["max"] = 255;
		
		$retour["page_track"]["defaut"] = "";
		$retour["page_track"]["js"] = "return false;";
		$retour["page_track"]["obligatoire"] = true;
		$retour["page_track"]["tri"] = true;
		$retour["page_track"]["filtre"] = true;

		$retour["language"]["id"] = "language";
		$retour["language"]["Affichage"] = "Langue";
		$retour["language"]["type"] = "input";
		$retour["language"]["max"] = 255;
		
		$retour["language"]["defaut"] = "";
		$retour["language"]["js"] = "return false;";
		$retour["language"]["obligatoire"] = true;
		$retour["language"]["tri"] = true;
		$retour["language"]["filtre"] = true;

		$retour["country"]["id"] = "country";
		$retour["country"]["Affichage"] = "Pays";
		$retour["country"]["type"] = "input";
		$retour["country"]["max"] = 255;
		
		$retour["country"]["defaut"] = "";
		$retour["country"]["js"] = "return false;";
		$retour["country"]["obligatoire"] = true;
		$retour["country"]["tri"] = true;
		$retour["country"]["filtre"] = true;

		$retour["abbrevcountry"]["id"] = "abbrevcountry";
		$retour["abbrevcountry"]["Affichage"] = "Abbréviation pays";
		$retour["abbrevcountry"]["type"] = "input";
		$retour["abbrevcountry"]["max"] = 255;
		
		$retour["abbrevcountry"]["defaut"] = "";
		$retour["abbrevcountry"]["js"] = "return false;";
		$retour["abbrevcountry"]["obligatoire"] = true;
		$retour["abbrevcountry"]["tri"] = true;
		$retour["abbrevcountry"]["filtre"] = true;

		$retour["city"]["id"] = "city";
		$retour["city"]["Affichage"] = "Ville";
		$retour["city"]["type"] = "input";
		$retour["city"]["max"] = 255;
		
		$retour["city"]["defaut"] = "";
		$retour["city"]["js"] = "return false;";
		$retour["city"]["obligatoire"] = true;
		$retour["city"]["tri"] = true;
		$retour["city"]["filtre"] = true;

		$retour["coordinates"]["id"] = "coordinates";
		$retour["coordinates"]["Affichage"] = "Coordonnées";
		$retour["coordinates"]["type"] = "input";
		$retour["coordinates"]["max"] = 255;
		
		$retour["coordinates"]["defaut"] = "";
		$retour["coordinates"]["js"] = "return false;";
		$retour["coordinates"]["obligatoire"] = true;
		$retour["coordinates"]["tri"] = true;
		$retour["coordinates"]["filtre"] = true;

		$retour["os"]["id"] = "os";
		$retour["os"]["Affichage"] = "OS";
		$retour["os"]["type"] = "input";
		$retour["os"]["max"] = 255;
		
		$retour["os"]["defaut"] = "";
		$retour["os"]["js"] = "return false;";
		$retour["os"]["obligatoire"] = true;
		$retour["os"]["tri"] = true;
		$retour["os"]["filtre"] = true;

		$retour["browser"]["id"] = "browser";
		$retour["browser"]["Affichage"] = "Navigateur";
		$retour["browser"]["type"] = "input";
		$retour["browser"]["max"] = 255;
		
		$retour["browser"]["defaut"] = "";
		$retour["browser"]["js"] = "return false;";
		$retour["browser"]["obligatoire"] = true;
		$retour["browser"]["tri"] = true;
		$retour["browser"]["filtre"] = true;

		$retour["referer"]["id"] = "referer";
		$retour["referer"]["Affichage"] = "Référant";
		$retour["referer"]["type"] = "input";
		$retour["referer"]["max"] = 255;
		
		$retour["referer"]["defaut"] = "";
		$retour["referer"]["js"] = "return false;";
		$retour["referer"]["obligatoire"] = true;
		$retour["referer"]["tri"] = true;
		$retour["referer"]["filtre"] = true;



		return $retour;
	}
	
	
	$this -> setvar('titre', 'Afficher un track');
	$this -> setvar('retour_url', rw(''));
	$this -> setvar('habilitation', habilitation());
	$this -> setvar('tableau', view($this -> table, $this -> id));
?>